<!-- eslint-disable vue/no-mutating-props -->
<template>
  <el-dialog
    v-model="props.toggle"
    :title="dialogtitle"
    :before-close="handleClose"
    :open="openDialog"
  >
    <el-form :model="form" label-width="120px" :disabled="isEdit">
      <el-form-item label="缴费时间">
        <el-input v-model="form.date" />
      </el-form-item>
    </el-form>
    <el-form :model="form" label-width="120px" :disabled="isEdit">
      <el-form-item label="住户姓名">
        <el-input v-model="form.name" />
      </el-form-item>
    </el-form>
    <el-form :model="form" label-width="120px" :disabled="isEdit">
      <el-form-item label="住户地址">
        <el-input v-model="form.address" />
      </el-form-item>
    </el-form>
    <el-form :model="form" label-width="120px" :disabled="isEdit">
      <el-form-item label="缴费金额">
        <el-input v-model="form.money" />
      </el-form-item>
    </el-form>
    <el-form :model="form" label-width="120px" :disabled="isEdit">
      <el-form-item label="缴费状态">
        <el-switch
          v-show="!isEdit"
          v-model="form.tag"
          class="ml-2"
          style="
            --el-switch-on-color: #13ce66;
            --el-switch-off-color: #ff4949;
            margin-right: 10px;
          "
        />
        <el-tag :type="form.tag ? 'success' : 'error'" disable-transitions>{{
          form.tag ? "已缴费" : "未缴费"
        }}</el-tag>
      </el-form-item>
    </el-form>
    <div>
      <el-button
        type="primary"
        v-show="!isEdit"
        @click="onSubmit"
        style="position: relative; left: 50px"
        >确认编辑</el-button
      >
    </div>
  </el-dialog>
</template>

<script setup>
import { defineProps, defineEmits, watch, reactive, onUpdated, ref } from "vue";
import { detailList } from "@/mockApi/homepage/MarkDetailData";
import { ElMessage } from "element-plus";

const props = defineProps({
  toggle: Boolean,
  tableData: Array,
  rowData: Object,
  dialogtitle: String,
  isEdit: Boolean,
});

const emit = defineEmits(["closeDialog"]);
// 关闭dialog方法
const handleClose = () => {
  emit("closeDialog");
};

// watch(props.toggle, (newValue) => {
//   this.dialogVisible = newValue;
// });

// 打开dialog
// const openDialog = () => {
//   form.id = props.rowData.id;
//   form.money = props.rowData.money;
//   form.date = props.rowData.date;
//   form.name = props.rowData.name;
//   form.address = props.rowData.address;
//   form.tag = props.rowData.tag;
//   console.log(form.money, "form.money");
// };

// 表单数据
const form = reactive({
  id: "",
  money: "",
  date: "",
  name: "",
  address: "",
  tag: "",
});
// switch
// const switchvalue = ref(true);

onUpdated(() => {
  // console.log(form, "onUpdated");
  form.id = props.rowData.id;
  form.money = props.rowData.money;
  form.date = props.rowData.date;
  form.name = props.rowData.name;
  form.address = props.rowData.address;
  form.tag = props.rowData.tag;
});

// 点击表单的编辑按钮时
const onSubmit = () => {
  // 获取/提交表单数据
  console.log(form, "onSubmit");
  detailList.set(form.id, form).then((res) => {
    emit("closeDialog");
    ElMessage.success("修改成功");
  });
};
</script>

<style lang="scss" scoped>
.el-table th {
  color: #000 !important; /* 字体颜色 */
  font-size: 16px;
  border: 0;
  height: 30px;
  line-height: 30px;
}
.el-table tr,
.el-table td {
  color: #000 !important;
  font-size: 12px;
  border: 0;
  height: 30px;
  line-height: 30px;
}
/* 上面两个背景色透明才能让table的背景透明少一个都不行 */

:deep(.el-table__body .success-row) {
  background-color: rgb(218, 218, 218) !important;
}

.el-form-item {
  margin-bottom: 10px;
}
</style>
